package com.atguigu.lease.common.springmvc;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandlers {

    @ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception e){
        //日志记录
        e.printStackTrace();
        //返回提示
        return Result.fail(e.getMessage());
    }

    //捕捉系统中的异常
    public Result<String> leaseExceptionHandler(LeaseException leaseException){
        //打印日志
        leaseException.printStackTrace();

        Result<String> result = Result.fail(leaseException.getCode(),leaseException.getMessage());
        return result;
    }
}
